package com.ksp.api.sqlscan;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;

public class KSPAPI_SqlScanThd implements Runnable{

	ConcurrentLinkedQueue<Map.Entry<String, Map<String, String>>> clsFildsQue;
	
	public static ReentrantLock deallock = new ReentrantLock(true);
	
	public KSPAPI_SqlScanThd(ConcurrentLinkedQueue<Map.Entry<String, Map<String, String>>> clsFildQue) {
		this.clsFildsQue = clsFildQue;
		// TODO Auto-generated constructor stub
	}
	
	
	
	@Override
	public void run() {
		while (!clsFildsQue.isEmpty()) {
			try {
				deallock.lock();
				Iterator<Entry<String, Map<String, String>>> clsFildMap = clsFildsQue.iterator();
				while (clsFildMap.hasNext()) {
					validSql(clsFildMap.next());
				}
				clsFildsQue.poll();
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				deallock.unlock();
			}
		}
	}
	
	public void validSql(Entry<String, Map<String, String>> clsFild) {
		String clsNam = clsFild.getKey();
		Map<String, String> fildMap = clsFild.getValue();
		Iterator<Entry<String, String>> iterator = fildMap.entrySet().iterator();
		while (iterator.hasNext()) {
			Entry<String, String> next = iterator.next();
			String sqlNam = next.getKey();
			String sqlVal = next.getValue();
			try {
				//执行类对应的sql，返回结果打印。
				executesql(sqlVal);
				System.out.println(clsNam + "," + sqlNam + "执行成功");
			} catch (Exception e) {
				System.out.println(clsNam + "," + sqlNam + "执行失败：" + e.getMessage());
				
			}
		}
	}



	private void executesql(String sqlVal) {
		// TODO Auto-generated method stub
		
	}
}
